package org.spring.boot.example.dds;

import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Ordered;
import org.springframework.util.Assert;

/**
 * 
 * <p>
 * 动态数据源增强器
 * </p>
 *
 * @author 吕潇
 * @date 2019-10-27
 */
public class DynamicDataSourceAdvisor implements InitializingBean, PointcutAdvisor, Ordered {

	private Advice advice;

	private Pointcut pointcut;

	@Override
	public Advice getAdvice() {
		return advice;
	}

	@Override
	public boolean isPerInstance() {
		return false;
	}

	@Override
	public Pointcut getPointcut() {
		return pointcut;
	}

	@Override
	public int getOrder() {
		return 0;
	}

	public void setAdvice(Advice advice) {
		this.advice = advice;
	}

	public void setPointcut(Pointcut pointcut) {
		this.pointcut = pointcut;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(advice, "Property 'advice' is required");
		Assert.notNull(pointcut, "Property 'pointcut' is required");
	}
}
